#!/usr/bin/env bash

TAG=$1
OUT=$2

. $(dirname $0)/util
set -eu -o pipefail

: ${PLATFORMS=}

usage() {
  echo "usage: ./hack/release-tar <tag> <out>"
  exit 1
}

if [ -z "$TAG" ] || [ -z "$OUT" ]; then
  usage
fi

platformFlag=""
if [ -n "$PLATFORMS" ]; then
  platformFlag="--platform=$PLATFORMS"
fi

buildxCmd build $platformFlag $cacheFromFlags \
  --target release \
  --output "type=local,dest=$OUT" \
  $currentcontext
